package com.allwees.bs.module.mms.entity;

import com.baomidou.mybatisplus.annotation.TableField;
import com.baomidou.mybatisplus.annotation.TableName;
import com.fasterxml.jackson.annotation.JsonIgnore;
import com.allwees.bs.core.modelbase.entity.WfBaseEntity;
import com.allwees.bs.module.core.constant.EWithdrawAccountChannel;
import com.allwees.bs.module.core.wf.WorkflowAware;
import com.allwees.core.common.constant.EPlatform;
import com.allwees.core.common.constant.EStatus;
import com.allwees.core.common.constant.EWithdrawAccountType;
import com.allwees.core.common.util.reflect.PojoUtil;
import lombok.Data;
import lombok.EqualsAndHashCode;

import javax.persistence.Column;

/**
 * 零售商
 *
 * @author yangylsky
 * @since 2019-12-11
 *
 */
@Data
@EqualsAndHashCode(callSuper = true)
@TableName("mms_retailer_apply")
public class RetailerApply extends WfBaseEntity implements WorkflowAware {

    private static final long serialVersionUID = 4914574760462208963L;
    /** 平台 **/
    private EPlatform platform;

    // ======== 公司信息=============

    private String storeName;

    private String firstName;

    private String lastName;

    private String workCountry;

    private String workProvince;

    private String workCity;

    private String workArea;

    @Column(columnDefinition = " text")
    private String workAddress;

    private String zipCode;

    /** 公司名称 **/
    private String companyName;

    /** 公司统一社会信用码 **/
    private String uniformSocialCreditCode;

    /** 营业执照 **/
    private String businessLicenseImg;

    /** 法人名称 **/
    @Column(length = 48)
    private String legalPersonName;

    @Column(length = 48)
    private String legalPersonIdCardNo;

    /** 手机号 **/
    @Column(length = 16)
    protected String mobile;

    /** 邮箱 **/
    @Column(length = 48)
    private String email;

    @JsonIgnore
    @Column(columnDefinition = "varchar(255)")
    private String password;

    /** 不通过原因 **/
    @Column(columnDefinition = " text")
    private String reason;

    private EWithdrawAccountChannel channel;
    private EWithdrawAccountType accountType;

    private String accountNo;
    private String bankCode;
    private String bankName;
    private String bankProvince;
    private String bankCity;
    private String bankArea;
    @Column(columnDefinition = " text")
    private String branchBankLocation;
    private String branchBank;

    private String accountOwnerName;
    private String accountOwnerIdNo;

    // 是否验证了邮箱:0 no,1 yes
    protected Integer emailVerified;

    /** 初审人 **/
    private String firstAuditUserUuid;

    /** 终审人 **/
    private String finalAuditUserUuid;

    /**
     * 1-公司零售 2-个人零售
     */
    private EWithdrawAccountType merchantType;

    /**
     * 关联类目
     */
    private String categoryNo;

    @TableField(exist=false)
    private String categoryFullname;

    public Retailer toRetailer() {
        Retailer retailer = PojoUtil.copy(new Retailer(), this);
        retailer.setIdentityVerified(1);
        retailer.setEmailVerified(1);
        retailer.setPhoneVerified(1);
        retailer.setPhone(getMobile());
        return retailer;
    }

    @JsonIgnore
    public boolean disabled() {
        return EStatus.DISABLED.getValue().equals(getStatus());
    }

    @JsonIgnore
    public boolean inAudit() {
        return EStatus.MMS_FIRST_AUDIT_APPROVED.getValue().equals(getStatus())
                || EStatus.WAIT_AUDIT.getValue().equals(getStatus());
    }

    @JsonIgnore
    public boolean rejected() {
        return EStatus.MMS_FINAL_AUDIT_REJECTED.getValue().equals(getStatus())
                || EStatus.MMS_FIRST_AUDIT_REJECTED.getValue().equals(getStatus());
    }

    @JsonIgnore
    public boolean approved() {
        return EStatus.NORMAL.getValue().equals(getStatus());
    }

    public String userName(){
        return getLastName() + " " + getFirstName();
    }

    @JsonIgnore
    public boolean emailVerified(){
        return getEmailVerified() != null && getEmailVerified() == 1;
    }
}
